package com.example.service.impl;
import java.math.BigDecimal;
import java.util.Date;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.Organization;
import com.example.mapper.OrganizationMapper;
import com.example.service.IOrganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Service
public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Organization> implements IOrganizationService {

    @Autowired
    private OrganizationMapper organizationMapper;

    @Override
    public List<Organization> getAllHotCompanies() {
        QueryWrapper<Organization> qw = new QueryWrapper<Organization>();
        qw.orderByDesc("org_est_date");
        List<Organization> organizationList = organizationMapper.selectList(qw);
        return organizationList;

    }

    @Override
    public void insert(Organization organization) {
        System.out.println(organization);
        organizationMapper.insert(organization);
    }

    @Override
    public void updateCompanyByComId(Long comId, Organization organization) {
        Organization org = organizationMapper.selectById(comId);
        org.setId(comId);
        org.setOrgUniCode(organization.getOrgUniCode());
        org.setOrgChiName(organization.getOrgChiName());
        org.setInduSmaPar(organization.getInduSmaPar());
        org.setOrgDele(organization.getOrgDele());
        org.setRegCap(organization.getRegCap());
        org.setOrgEstDate(organization.getOrgEstDate());

        QueryWrapper<Organization> qw = new QueryWrapper<Organization>();
        qw.eq("id",comId);
        organizationMapper.update(org,qw);

    }

    @Override
    public void deleteCompanyByComId(Long comId) {
        QueryWrapper<Organization> qw = new QueryWrapper<>();
        qw.eq("id",comId);
        organizationMapper.delete(qw);
    }

}
